package mistags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.TagSupport;

public class WithAttribBodyTag extends TagSupport implements BodyTag {
	protected String apellido = null;
	private String contenido;
	
	public String getApellido() {
		return apellido;
	}

	public void setApellido(String apellido) {
		this.apellido = apellido;
	}
	
	@Override
	public int doStartTag() throws JspException {
		try {
			JspWriter out = pageContext.getOut();
			out.print("Producido desde OtroTag, apellido=" + apellido);
			} catch(IOException ioe) {
			System.out.println("Error in ExampleTag: " + ioe);
			}
			return(EVAL_BODY_INCLUDE);
	}

  
@Override
public void doInitBody() throws JspException {
	JspWriter out = pageContext.getOut();
	try {
		out.print(contenido);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}

@Override
public void setBodyContent(BodyContent arg0) {
	contenido = arg0.getString();
}	

}
